%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This file runs the cleaning functions on the raw fighters data%%
%%and issues a file with outputs of main variables%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear  out A B C D E;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Here we use the matching function on country names, education levels, Civil Status%% 
%% Religious level, aspiration in ISIS, previous employment and Jihad Experience%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[country_origin, replacements] = matching(Nationality,Country_univ);
[level_educ, replacements_ed] = matching(EducationLevel,Education_univ);
[civil_stat, replacements_mar] = matching(CivilStatues,Marriage);
[level_rel, replacements_rel] = matching(Religiouslevel,religion);
[aspirations, replacements_asp] = matching(TypeofOccupationinISIS,aspiration_univ);
[Job_cl, replacements_job] = matching(Job,Job_univ);
[Experience_cl, replacements_exp] = matching(ExperienceinJihad,Experience_univ);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setting up the output variables for the file%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


out{1,1} = 'Nationality';
out{1,2} = 'country_origin';
out{1,3} = 'replacements';
A = [Nationality country_origin replacements];

out{1,4} = 'Education';
out{1,5} = 'Education_cl';
out{1,6} = 'replacements_ed';
B = [EducationLevel level_educ replacements_ed];

out{1,7} = 'CivilStatus';
out{1,8} = 'CivilStatus_cl';
out{1,9} = 'replacements_mar';
C = [CivilStatues civil_stat replacements_mar];

out{1,10} = 'ReligiousLevel';
out{1,11} = 'ReligiousLevel_cl';
out{1,12} = 'replacements_rel';
D = [Religiouslevel level_rel replacements_rel];

out{1,13} = 'Aspiration_ISIS';
out{1,14} = 'Aspiration_cl';
out{1,15} = 'replacements_asp';
E = [TypeofOccupationinISIS aspirations replacements_asp];

out{1,16} = 'Job';
out{1,17} = 'Job_cl';
out{1,18} = 'replacements_job';
F = [Job Job_cl replacements_job];

out{1,19} = 'ExperienceinJihad';
out{1,20} = 'Experience_cl';
out{1,21} = 'replacements_exp';
G = [ExperienceinJihad Experience_cl replacements_exp];

out{1,22} = 'ID';
out{1,23} = 'YearofBirth';

H = [A B C D E F G ID YearofBirth];
out = [out; H];

xlswrite('data_fighters',out);